home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 477 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.4 KB  |  49 lines

  1. Newsgroups: comp.lang.c
  2. Path: news3.noc.netcom.net!zdc!zippo!usenet
  3. From: Jim McFarland <jgm6@orkand.em.cdc.gov>
  4. Subject: Re: extern and static are they compatable
  5. Content-Type: text/plain; charset=us-ascii
  6. Sender: usenet@news.zippo.com
  7. Content-Transfer-Encoding: 7bit
  8. Nntp-Posting-Host: 158.111.166.77
  9. Organization: The Orkand Corporation
  10. Message-ID: <DKprxq.GFG@news.zippo.com>
  11. References: <4cedhf$g6i@cnn.cc.biu.ac.il> <ahicksDKM8Ap.FBp@netcom.com> <4ci3ao$f84@news.gate.net>
  12. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  13. Mime-Version: 1.0
  14. Date: Fri, 5 Jan 1996 15:20:05 GMT
  15.  
  16. bhutto@gate.net (William Hutto) wrote:
  17. >In article <ahicksDKM8Ap.FBp@netcom.com>,
  18. >   ahicks@netcom.com (Aaron Hicks at Netcom) wrote:
  19. >>Folks,
  20. >>
  21. >>  I'm working on a project which requires use to create large array 
  22. >>( approximately 500 K bytes ) so we decided to make it static so it would  
  23. >>not have be created each time the routines that use it are called.  
  24.  
  25. The "static" keyword actually has two different uses, which you seem to be confusing 
  26. here.  When used in global scope, static does as those who previously replied to you post 
  27. have noted... it limits the scope of the variable to the source file it is declared in.  
  28. When static is used in an automatic variable declaration (i.e. within a function) then 
  29. you get the behavior you describe, i.e. the variable is initialized once and retains its 
  30. value between calls to the function.  However to do what you actually describe, i.e. 
  31. create a global variable for use by several functions, static is not needed unless you 
  32. want to limit the scope of the variable to that one source file.  Since you later needed 
  33. to access the variable from another source file, as others have pointed out, static 
  34. cannot be used.  Does that help clear things up any?
  35.  
  36. >>We then
  37. >>found out that we needed a nother program to acess this array so in the 
  38. >second
  39. >>file we defined this array as a extern.  Now each time we compile and link 
  40. >>the programs we get an error stating that the array is undefined.  The error
  41. >>is displayed while linking.  After reading all I could find about extern 
  42. >>I can not find any thing that says this is correct behavior.  I then changed 
  43. >>the static decloration to a non static and the thing compiles with out a 
  44. >>problem.  Now I'm wandering if any of the great mind on the net could 
  45. >>enlighten me as to why the static declaration would cause this error.  
  46. >
  47.  
  48.  
  49.